package com.gph.saviorframework.activiti.extension.identity;

import com.gph.saviorframework.security.service.RoleService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.GroupQuery;
import org.activiti.engine.impl.GroupQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.persistence.AbstractManager;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.GroupIdentityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class CustomGroupEntityManager extends AbstractManager implements GroupIdentityManager {

	@Autowired
	RoleService roleService;

	public Group createNewGroup(String groupId) {
		return null;
	}

	public void insertGroup(Group group) {
		
	}

	public void updateGroup(Group updatedGroup) {
		
	}

	public void deleteGroup(String groupId) {
		
	}

	public GroupQuery createNewGroupQuery() {
		return null;
	}

	public List<Group> findGroupByQueryCriteria(GroupQueryImpl query, Page page) {
		return null;
	}

	public long findGroupCountByQueryCriteria(GroupQueryImpl query) {
		return 0;
	}

	public List<Group> findGroupsByUser(String userId) {
		List<Group> groups = new ArrayList<Group>();
		List<Map<String, Object>> roles = roleService.findByUser(userId);
		for(Map<String, Object> role : roles) {
			GroupEntity ge = new GroupEntity();
			ge.setId(role.get("id").toString());
			ge.setName(role.get("name").toString());
			groups.add(ge);
		}
		return groups;
	}

	public List<Group> findGroupsByNativeQuery(
			Map<String, Object> parameterMap, int firstResult, int maxResults) {
		return null;
	}

	public long findGroupCountByNativeQuery(Map<String, Object> parameterMap) {
		return 0;
	}

	public boolean isNewGroup(Group group) {
		return false;
	}

}
